<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>支付管理</el-breadcrumb-item>
      <el-breadcrumb-item>支付列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入订单号" v-model="queryInfo.query">
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="handleQueryOrder()"
            ></el-button> </el-input
        ></el-col>
      </el-row>

      <el-table :data="payList" border style="width: 100%">
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="id" label="id"> </el-table-column>
        <el-table-column prop="order_id" label="订单号"> </el-table-column>
        <el-table-column prop="price" label="支付金额(元)"> </el-table-column>
        <el-table-column prop="create_time" label="支付时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pageNum"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="queryInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pageNum: 1,
        pageSize: 5
      },
      payList: [],
      total: 0
    }
  },
  created() {
    this.getPayList()
  },
  methods: {
    async getPayList() {
      const { data: res } = await this.$http.get('/getPaymentListByOrderId', {
        params: this.queryInfo
      })
      if (res.status !== 200) {
        this.$message.error('获取支付列表失败')
        return
      }
      this.payList = res.data.data
      this.total = res.data.totalNum
      this.$message.success('获取列表成功')
    },
    handleQueryOrder() {
      this.queryInfo.pageNum = 1
      this.getPayList()
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize
      this.getPayList()
    },

    handleCurrentChange(newPage) {
      this.queryInfo.pageNum = newPage
      this.getPayList()
    }
  }
}
</script>

<style lang="less" scoped></style>
